<template>
  <!--新增产品线-->
  <el-dialog
    :close-on-click-modal="false"
    title="邀请报价"
    :visible.sync="dialogVisible"
    @close="handleClose"
    width="380px"
  >
    <el-form
      size="mini"
      :model="formDate"
      label-width="100px"
      ref="ruleForm"
      :rules="rules"
    >
      <el-form-item label="采购员:" prop="purchaseUserIds">
        <el-select
          v-model="formDate.purchaseUserIds"
          multiple
          filterable
          @focus="getSalesMemberList"
          :loading="salesmanLoading"
        >
          <el-option
            v-for="item in salesMemberList"
            :key="item.userId"
            :value="item.userId"
            :label="item.userName"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose" size="small">取 消</el-button>
      <el-button
        type="primary"
        @click="handleConfirm"
        :loading="btnLoading"
        size="small"
        >确认</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import { getOrderUsersList } from '@/api/partner'
import { inquiryOperate } from "@/api/allInLine/inquiry.js";
import { Message } from "element-ui";
const defaultSendForm = {
  inquiryId: "",
  operateType: "invitePrice",
  purchaseUserIds: [],
};
export default {
  name: "addQuotationMember",
  data() {
    return {
      dialogVisible: false,
      btnLoading: false,
      // 表单参数
      formDate: JSON.parse(JSON.stringify(defaultSendForm)),
      // 产品线列表
      categoryList: [],
      categoryLoading: false,
      // 人员列表
      salesMemberList: [],
      salesmanLoading: false,
      rules: {
        categoryId: [
          {
            required: true,
            message: "产品线名称不能为空",
            trigger: ["change"],
          },
        ],
        purchaseUserIds: [
          { required: true, message: "人员名称不能为空", trigger: ["change"] },
        ],
      },
    };
  },
  methods: {
    // 获取人员列表
    async getSalesMemberList() {
      this.salesmanLoading = true;
      const res = await getOrderUsersList({
        departmentType:"purchase"
      });
      this.salesmanLoading = false;
      this.salesMemberList = res;
    },
    // 确认提交
    handleConfirm() {
      const data = JSON.parse(JSON.stringify(this.formDate));
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          inquiryOperate(data)
            .then((res) => {
              Message.success("邀请报价成功");
              this.btnLoading = false;
              this.handleClose();
              this.$emit("update");
            })
            .catch((err) => {
              this.btnLoading = false;
            });
        }
      });
    },
    // 关闭弹框
    handleClose() {
      this.dialogVisible = false;
      this.formDate = JSON.parse(JSON.stringify(defaultSendForm));
      this.$refs.ruleForm.resetFields();
    },
  },
};
</script>

<style  lang="scss">
</style>
